Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: ['../../img/no/hun.jpg', '../../img/no/hun.jpg'],
    meals: [],
    pageSize: 2,
    pageNumber: 1 
  }, 

  // 修复swiper高度不能自适应问题
  imageLoad: function (e) {
    var res = wx.getSystemInfoSync();
    var imgwidth = e.detail.width,
      imgheight = e.detail.height + 44 * res.windowWidth / 750,
      ratio = imgwidth / imgheight;
    this.setData({
      bannerHeight: res.windowWidth / ratio
    })
  },

  // 拨打热线电话
  hotLine: function () {
    wx.makePhoneCall({
      phoneNumber: '400-6860-588'
    })
  },

  // 跳转到详情
  toDetails2: function (e) {
    var mealId = e.currentTarget.dataset.value
    wx.navigateTo({
      url: '../details2/details2?mealId=' + mealId
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadMeal()
    this.loadImages()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let pageNumber = this.data.pageNumber

    pageNumber = pageNumber + 1
    this.setData({
      pageNumber: pageNumber
    });
    this.loadMeal()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '琼崖租车',
      path: '/pages/index/index'
    }
  },
  loadMeal: function () {
    let that = this
    //加载推荐商品
    wx.request({
      url: 'https://small.qiongyazuche.com/sunday/small/meal/select',
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        'pageSize': that.data.pageSize,
        'pageNumber': that.data.pageNumber,
        'type': 2
      },
      success: function (res) {
        let meals = that.data.meals.concat(res.data.result.data)
        that.setData({
          meals: meals
        })
      }
    })

  }, loadImages: function () {
    let that = this
    //加载推荐商品
    wx.request({
      url: 'https://small.qiongyazuche.com/sunday/small/advertisement/getAdvertisementByZoneKey',
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        'zoneKey': 'hunqing_roll'

      },
      success: function (res) {
        that.setData({
          images: res.data.result
        })
      }
    })
  }
})